﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WorldOnFire
{
    public class CBomb : ABCProjectile
    {
        private Vector3[] m_vGravityNormal;

        private const float BOMB_INITIAL_SPEED = 2.5f;
        private const float BOMB_ACCELERATION = 10.0f;

        public override void Initialize(int _nObjectCount)
        {
            // Initialize the base members
            base.Initialize(_nObjectCount);

            // Initialize the arrays
            m_vGravityNormal = new Vector3[_nObjectCount];

            // Set the enumerations
            eBaseType[] eBaseTypes = new eBaseType[] { eBaseType.MOVING_OBJECT, eBaseType.PROJECTILE };
            this.SetBaseTypeID(eBaseTypes);

            this.SetObjectType(eObjectType.PROJECTILE_BOMB);
            this.SetProjectileID(eProjectileType.BOMB);

            // Assign collidable types
            m_CollidableTypeList.Add(eObjectType.TARGET);
        }

        public override void LoadContent()
        {
            m_eModelID = CRenderingManager.eModelID.PROJECTILE_EMP;
            
            base.LoadContent();
        }

        public override void Update(float _fDeltaTime)
        {
            // Loop through each bomb
            for (int iBomb = 0; iBomb < m_nObjectCount; ++iBomb)
            {
                // Accelerate
                m_fSpeed[iBomb] += BOMB_ACCELERATION * _fDeltaTime;

                // Fall towards the target
                m_mTransform[iBomb].Translation += m_vGravityNormal[iBomb] * m_fSpeed[iBomb] * _fDeltaTime;
            }

            // Update the base members
            base.Update(_fDeltaTime);
        }

        protected override void InitializeProjectile(int _nProjectileIndex, ABCEnemy _Enemy, int _nEnemyIndex, Vector3 _vOffset)
        {
            // Initialize the base members
            base.InitializeProjectile(_nProjectileIndex, _Enemy, _nEnemyIndex, _vOffset);

            // Set the direction of gravity (Enemy Z Axis)
            m_vGravityNormal[_nProjectileIndex] = _Enemy.GetTransform(_nEnemyIndex).Backward;

            // Reset the speed
            m_fSpeed[_nProjectileIndex] = BOMB_INITIAL_SPEED;

            // TODO: FORMULA OR SOMETHING
            m_fMaximumTime[_nProjectileIndex] = 3.0f;
        }
    }
}
